﻿using System;
using System.Windows.Forms;

namespace YArchitech.Controls
{
	public class HYGridViewNumbericCell : DataGridViewTextBoxCell
	{
		public bool IsInt { get; set; }

		public bool IsPositive { get; set; }

		public MostValue ValueRange { get; set; }

		public HYGridViewNumbericCell()
		{
			this.ValueRange = new MostValue(0.0, 0.0);
		}

		public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
		{
			base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
			HYGridViewNumbericEditingControl hygridViewNumbericEditingControl = base.DataGridView.EditingControl as HYGridViewNumbericEditingControl;
			DataGridViewColumn owningColumn = base.OwningColumn;
			if (owningColumn is HYGridViewNumbericColumn)
			{
				HYGridViewNumbericColumn hygridViewNumbericColumn = owningColumn as HYGridViewNumbericColumn;
				hygridViewNumbericEditingControl.IsInt = (hygridViewNumbericColumn.IsInt ? NumberType.integer : NumberType.doubles);
				hygridViewNumbericEditingControl.IsPositive = (hygridViewNumbericColumn.IsPositive ? SymbolSelect.positive : SymbolSelect.none);
				hygridViewNumbericEditingControl.MostValue = hygridViewNumbericColumn.ValueRange;
				hygridViewNumbericEditingControl.Text = ((base.Value == null || "" == base.Value.ToString()) ? "0" : base.Value.ToString());
			}
		}

		public override Type EditType
		{
			get
			{
				return typeof(HYGridViewNumbericEditingControl);
			}
		}

		protected static bool BoolFromTri(DataGridViewTriState tri)
		{
			return tri == DataGridViewTriState.True;
		}
	}
}
